<!DOCTYPE html>
<html>
<head>
    <title>用户中心</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <meta charset="utf-8" />
    <meta content="initial-scale=1.0,user-scalable=no,maximum-scale=1,width=device-width" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <link href="Css/style.css" rel="stylesheet" type="text/css">
    <link href="Css/usercenter.css" rel="stylesheet" type="text/css">
    <script src="Scripts/http.js"></script>
    <script type="text/javascript" src="Scripts/jquery-1.8.3.min.js"></script>
    <link rel="stylesheet" href="Css/common.css">
    <script type="text/javascript" src="Scripts/alertPopShow.js"></script>
    <script>
        $(function(){
            var allphone='';
            var openid ='';
            getuserinfo();
            function getuserinfo(){
                $.ajax({
                    url:url+'getuserinfo',
                    dataType:'json',
                    type:'post',
                    async:false,
                    data:{},
                    success:function(result){
                        // console.log(result);
                        var status = result.status;
                        var code = result.code;
                        if(status==1&&code=='1001'){
                            var userinfo = result.data;
                            if(userinfo!=null){
                                var html = '<img src="'+userinfo['img']+'"/>';
                                openid = userinfo['openid'];
                                $('.user-img').html(html);
                                $('.user-name').html(userinfo['username']);
                                var intergral = userinfo['integral'];//用户积分
                            }

                            var integrals = result.integrals;//积分配置
                            if(intergral>=integrals[5]['value']){
                                $('.user-level').html('金卡会员');
                            }else if(intergral>=integrals[4]['value']){
                                $('.user-level').html('银卡会员');
                            }else{
                                $('.user-level').html('普通会员');
                            }

                            html='<strong>您当前的积分:'+userinfo['integral']+'</strong><span></span>';
                            $('.jifen').html(html);
                            var usercenter = result.usercenter;
                            aftersale = usercenter['aftersale'];
                           sessionStorage.setItem('rexian',aftersale);
                            $('.wait-kefu').attr('href','tel:'+usercenter['aftersale']);
                            $('.helpCenterinfo').html(usercenter['helpsenter']);
                            allphone =userinfo['phone'];
                            if(userinfo['phone']==''){
                                alertphone('');
                            }
                        }
                    },
                    error:function(result) {
                        console.log("error")
                    }
                });
            }
            $('.user-phone').on('click', function(){
               if(allphone==''){
                   alertphone('');
               }else{
                   alertphone(allphone);
               }

            });
            function alertphone(phone){
                var html = "<label>手机号：<input class='confirm_input' placeholder='请输入手机号：' value='"+phone+"'></label>";
                popTipShow.confirm('绑定手机号',html,['确 定','取 消'],
                        function(e){
                            //callback 处理按钮事件
                            var button = $(e.target).attr('class');
                            if(button == 'ok'){
                                if(null==$(".confirm_input").val() || ""==$(".confirm_input").val()){
                                    webToast("手机号不能为空！","bottom", 3000);
                                    return;
                                }

                                var phone = $(".confirm_input").val();
                                if(!(/^1[34587]{1}\d{9}$/.test(phone))){
                                    alert("输入的手机号有误，重新输入");
                                    return false;
                                }
                                this.hide();
                                //按下确定按钮执行的操作
                                $.ajax({
                                    url:url+'addphone',
                                    dataType:'json',
                                    type:'post',
                                    async:false,
                                    data:{'openid':openid,'phone':phone},
                                    success:function(result){
                                        // console.log(result);
                                        var status = result.status;
                                        var code = result.code;
                                        if(status==1&&code=='1001'){
                                            allphone = phone;
                                            setTimeout(function() {
                                                webToast('绑定成功！',"bottom", 3000);
                                            }, 100);
                                        }
                                    },
                                    error:function(result) {
                                        console.log("error")
                                    }
                                });
                            }

                            if(button == 'cancel') {
                                //按下取消按钮执行的操作
                                //todo ....
                                this.hide();
                            }
                        }
                );
            }
            $('.user-helpcenter').on('click', function(){
                var content = $('.helpCenterinfo').html();
                alert(content);return;
                /*popTipShow.alert('帮助中心',content, ['知道了'],
                        function(e){
                            //callback 处理按钮事件
                            var button = $(e.target).attr('class');
                            if(button == 'ok'){
                                //按下确定按钮执行的操作
                                //todo ....
                                this.hide();
                            }
                        }
                );*/
            });
        })

    </script>
</head>
<body>

    <div class="yintai-header">
        <a href="javascript:void(0);" class="back-button"></a>
        <div class="hear-name">用户中心</div>
        <div class="xiala"><span></span></div>
    </div>

    <div class="viewport">

        <div class="user-information">
            <div class="user-img"><img src="http://r.ytrss.com/mobile/img/user-head.png" /></div>
            <p class="user-name"></p>
            <p class="user-level"></p>
            <p class="jifen" style="text-align: center;margin-top: 10px;color: #f2f2f2"></p>
        </div>
        <div class="user-order cf">
            <a href="orders.html?status=0" class="allorder"><span><i></i>全部订单</span></a>
            <a href="orders.html?status=1" class="wait-pay"><span><i></i>待付款</span></a>
            <a href="orders.html?status=2" class="wait-shouhuo"><span><i></i>待收货</span></a>
            <a href="tel:4001191111" class="wait-kefu"><span><i></i>客服电话</span></a>
        </div>
        <div class="user-common user-phone" style="margin-top: 10px;">
            <a class="yintai-phone" href="javascript:void(0);">绑定手机号<div class="infor-phone"><span class="pink"></span></div><em></em></a>
            <div class="hr"></div>
        </div>
        <div class="user-helpcenter user-common">
            <a class="hc-helpCenter" href="javascript:void(0);">帮助中心<em></em></a>
            <p class="helpCenterinfo" style="display: none;">帮助中心</p>
        </div>
        <div class="user-orders user-common">
            <a class="hc-helpCenter" href="orderchange.html">修改订单<em></em></a>
            <p class="helpCenterinfo" style="display: none;">修改订单</p>
        </div>
    </div>
    



</body>
</html>
